<template>
  <div class="dt-main-tabs-content">
    <div class="dt-content-main">
      <div class="dt-content-head">
        <div class="dt-content-head-tab">
          <div>
            <!-- <span class="dt-head-title" @click="goBack">
              <i class="el-icon-arrow-left"></i>
              返回
            </span>
            <em></em> -->
            <span class="dt-head-title">审批详情</span>
          </div>
        </div>
      </div>
      <div class="dt-content-page">
        <MaComProgressDetail :approvalDetial="approvalDetial" @dataChange="dataChange"></MaComProgressDetail>
        <MaComApprovalRecord :appovalRecord="appovalRecord"></MaComApprovalRecord>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      Uid: this.$tools.getDecrypt(this.$store.state.uid), //用户id,
      approvalDetial: {}, //审批详情
      appovalRecord: {} //审批记录
    }
  },
  computed: {
    query() {
      return this.$tools.getQuery(this)
    }
  },
  methods: {
    goBack() {
      // console.log(this.query)
      this.$router.push('/main/#/ma?tab=list&elTab=' + this.query.elTab)
    },
    // getApprovalDetail() {
    //   if (this.query.auditType == '2') {
    //     var data = [{ userId: this.Uid, taskId: this.query.taskId }],
    //       domain = [this.$store.state.DOMAIN],
    //       path = ['/project/taskAudit/auditProgressDetail'],
    //       dataAxios = this.$tools.getDataAxios(this, domain, path, data)
    //     Promise.all(dataAxios)
    //       .then((response) => {
    //         this.$tools.callbackAxios(this, response, (response) => {
    //           var data = response[0].data
    //           if (data.code === 200) {
    //             this.AuditList = data.data.items
    //             this.TotalRecord = data.data.total_record
    //             this.TotalPage = data.data.total_page
    //           }
    //         })
    //       })
    //       .catch((error) => {})
    //   }
    //   if (this.query.auditType == '1') {
    //     var data = [{ userId: this.Uid, taskId: this.query.taskId }],
    //       domain = [this.$store.state.DOMAIN],
    //       path = ['/project/taskAudit/auditDrawingDetail'],
    //       dataAxios = this.$tools.getDataAxios(this, domain, path, data)
    //     Promise.all(dataAxios)
    //       .then((response) => {
    //         this.$tools.callbackAxios(this, response, (response) => {
    //           var data = response[0].data
    //           if (data.code === 200) {
    //             this.AuditList = data.data.items
    //             this.TotalRecord = data.data.total_record
    //             this.TotalPage = data.data.total_page
    //           }
    //         })
    //       })
    //       .catch((error) => {})
    //   }
    // },
    getApprovalDetail(taskAuditId = this.query.taskAuditId) {
      // 定义共同的变量
      const domain = [this.$store.state.DOMAIN]
      let path
      // 根据auditType决定路径
      if (this.query.auditType === '2') {
        var data = [{ userId: this.Uid, taskId: this.query.taskId, taskAuditId: taskAuditId }]
        path = ['/project/taskAudit/auditProgressDetail']
      } else if (this.query.auditType === '1') {
        var data = [{ userId: this.Uid, taskAuditId: taskAuditId }]
        path = ['/project/taskAudit/auditDrawingDetail']
      }

      // 如果路径被正确设置，则执行请求
      if (path) {
        const dataAxios = this.$tools.getDataAxios(this, domain, path, data)
        Promise.all(dataAxios)
          .then((response) => {
            this.$tools.callbackAxios(this, response, (response) => {
              const data = response[0].data
              if (data.code === 200) {
                this.approvalDetial = data.data
                this.appovalRecord = data.data
              }
            })
          })
          .catch((error) => {
            // 处理错误情况
          })
      }
    },
    dataChange(taskAuditId) {
      this.getApprovalDetail(taskAuditId)
      if (taskAuditId) {
        if (this.query.auditType === '2') {
          this.$router.push(
            '/main/#/ma?tab=detail&elTab=' +
              this.query.elTab +
              '&taskId=' +
              taskAuditId +
              '&auditType=' +
              this.query.auditType +
              '&taskAuditId=' +
              taskAuditId
          )
        } else {
          this.$router.push('/main/#/ma?tab=detail&elTab=' + this.query.elTab + '&taskAuditId=' + taskAuditId + '&auditType=' + this.query.auditType)
        }
      }

      // this.$router.push('/main/#/ma?tab=list&elTab=' + this.query.elTab)
    }
  },
  watch: {
    $route(to, from) {
      // 当路由发生变化时，这个函数会被调用
      // to 和 from 分别代表路由对象和之前的路由对象
      this.getApprovalDetail()
      // console.log('路由变化:', to, from)
    }
  },
  mounted() {
    this.getApprovalDetail()
  }
}
</script>
<style scoped>
.dt-content-page {
  margin: 0;
  background-color: #f2f3f5;
  padding: 16px;
  display: flex;
  flex-direction: row;
}
.dt-content-head-tab em {
  height: 16px;
  width: 1px;
  display: inline-block;
  background-color: #e9eef7;
  margin: 0 16px;
}
.dt-content-head-tab > div {
  display: flex;
  align-items: center;
}
.dt-head-title {
  width: auto;
}
.dt-head-title i {
  line-height: 51px;
}
</style>
